﻿using GodSystemBLL;
using GodSystemCommon;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GodSystem.FormChildren
{
    public partial class FormCateAdd : Form
    {
        public FormCateAdd()
        {
            InitializeComponent();
        }

        private void button_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        private void button_Add_Click(object sender, EventArgs e)
        {
            string cateName = textBox_CateName.Text.Trim();
            if (string.IsNullOrEmpty(cateName))
            {
                MessageBox.Show("分类名称不能为空","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
            CateBLL cateBLL = new CateBLL();
            int num = Convert.ToInt32(cateBLL.CheckCateName(cateName));
            if(num > 0)
            {
                MessageBox.Show("分类名称已经存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int result = cateBLL.AddCate(cateName, GlobalData.UsersName);
            if(result > 0)
            {
                MessageBox.Show("分类添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBox_CateName.Text = "";
            }
            else
            {
                MessageBox.Show("分类添加失败，请重试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }
    }
}
